In [1]:
import tensorflow as tf

In [7]:
# abs
# To get absolute value of a Tensor or placeholder or scalar
x = tf.constant([[-3, 3], [2, -3 - 4j]])

val = tf.abs(x, name = 'abs')

sess = tf.Session()
sess.run(val)


Out[7]:
array([[ 3.,  3.],
       [ 2.,  5.]])

In [9]:
# accumulate_n
# To get element wise sum of a tensor
x = tf.constant([[2,4], [3,1]])
y = tf.constant([[5,0], [2,3]])

val = tf.accumulate_n([x,y], shape=[2,2], tensor_dtype = tf.int32, name='accumuate_n')

sess.run(val)
# It is not differentiable as it calculates the sum as the inputs are
# provided. To get differentiable output use add_n


Out[9]:
array([[7, 4],
       [5, 4]], dtype=int32)

In [10]:
# acos
# To get element wise cos of all elements

# acosh

In [12]:
# add
# To add two tensors
# It supports broadcasting
x = tf.constant([1,2])
y = tf.constant([[1,2], [3,4]])

val = tf.add(x, y, name = 'add')

sess.run(val)


Out[12]:
array([[2, 4],
       [4, 6]], dtype=int32)

In [21]:
# add_n
# To do the same operation as add except broadcasting is not allowed
# It takes list as an input
val = tf.add_n([y, y, y])

sess.run(val)


Out[21]:
array([[ 3,  6],
       [ 9, 12]], dtype=int32)

In [22]:

Tensor operations


In [ ]:
# Casting
tensor = tf.